<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计时器</title>
</head>
<body >
<H1>写一个计时器</H1>
<hr>
    <button id="btn1" onclick="stopWin()">结束键</button>
<button id="btn100" onclick="myWin()">开始键</button>
    <button id="btn" onclick="stopTime()">按钮</button>
    <p id="ptime"></p>
    <script>
        // var mytime=setInterval(function () {
        //     getTime();
        // },1000);//1000毫秒
        // function getTime(){
        //     var d=new Date();
        //     var t=d.toLocaleTimeString();//时分秒转化成字符串
        //     document.getElementById("ptime").innerHTML=t;
        // }
        // function stopTime() {
        // clearInterval(mytime);
        // }//点击按钮即停止计时
        var win;
        function myWin() {
            alert("hello");
        win=setTimeout(function(){myWin()},3000);}
        function stopWin() {
            clearTimeout(win);//清除变量
        }
    </script>
</body>
</html>